<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
    <meta content=always name=referrer>
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/newbase.css">
    <script src="__STATIC__/js/jquery-1.8.2.js"></script>
    <title>确认订单</title>
    <script>
        $(function () {
            if ('{:count($data)}' == 0){
                window.location.href=sessionStorage.getItem('goods_order_yes_url');
            }
            $(".chose").toggle(
                function () {
                    $(this).attr("src","__STATIC__/img/1234.png")
                },
                function () {
                    $(this).attr("src","__STATIC__/img/123.png")
                }
            )
            sessionStorage.setItem('cart_id',"{:input('cart_id')}");
            sessionStorage.setItem('coupon_id','{:input("coupon_id","")}');
            sessionStorage.setItem('red_packet_id',"{:input('red_packet_id','')}");
            sessionStorage.setItem('address_id',"{:input('address_id')}");
            sessionStorage.setItem('goods_str','{$goods_str}');
        })
    </script>
</head>
<body>
<div class="wrap-ord-det">
    <div class="header">
        <p>确认订单</p>
        <img src="__STATIC__/img/back.png" class="back" onclick="back_url()">
    </div>
<form action="" method="post" id="form" >
    <div class="center">
        <div class="address">
        {if condition="$address"}
            <span>收货人</span>
            <p>{$address.name}    {$address.phone}<span><a href="javascript:change_address();"><img src="__STATIC__/img_user/next2.png"></a></span></p>
            <p id="address_info">{$address.area_info} <br/> {$address.address}</p>
            {else/}
            <a href="javascript:change_address();">
                <p style="text-align: center;color: #212121;"><img style="vertical-align: middle;" src="__STATIC__/img_user/go_jump.png" />去选择收货地址</p>
            </a>
        {/if}
        </div>

    </div>
    {volist name='data' id='item' key="k"}
    <div class="main">
        <h4>
            <a href="javascript:jump_shop({$item['shop_id']});"><span>店铺名称: {$key}  </span><img src="__STATIC__/img_user/next2.png"></a>
            {if condition="input('?combo') "}
            <span style="color: #E73F09;border: 1px solid #E73F09;;border-radius:10%;padding:0 5px ;line-height: 1.5;margin: 13px 15px 0 0;float: right;font-size: 12px;"><a href="javascript:void(0);" style="color: #E73F09;">套餐</a></span>
            {/if}
        </h4>

        <input type="hidden" id="shop_id_{$k}" name="shop_id[]" value="{$item['shop_id']}" />
        {volist name='item.data' id='v'}
        <div class="content">
            <a href="javascript:jump_goods_details({$v.shopGoods.id});">
                <div class="left">
                    <img src="/{$v.shopGoods.thumb_img}" onerror=this.src="/static/mobile/img/empty_img.png" >
                </div>
                <div class="right">
                    <div class="title">
                        <p>{$v.shopGoods.title}
                            {if condition="$v.limited_status eq 1"}
                            <span style="color: #E73F09;border: 1px solid #E73F09;;border-radius:10%;padding:0 5px ;">特</span>
                            {/if}
                        </p>

                    </div>
                    <p class="type">属性规格: {if condition="$v.attr"}{$v.attr}{else/}无属性{/if}<span>×{$v.number}</span></p>
                    <div class="price">
                        <div>&yen;<font class="price}">{$v.price}</font></div>

                    </div>
                </div>
            </a>
        </div>
        {/volist}
    </div>
    <ul class="list">
        {if condition="!input('?limited')"}
        {if condition="!input('?combo')"}
        <li>
            <span>优惠券</span><p>{if condition="$item.coupon_id"}<img src="__STATIC__/img_user/new_close.png" style="float: left;margin:12.5px 10px 0 0;vertical-align:middle;" onclick="del_choose({$item.coupon_id})" />{/if}<a href="javascript:choose_ticket({$k});"><span>{if condition="$item.coupon_id"}{$item.coupon_title}{else/}使用优惠券{/if} </span><img src="__STATIC__/img_user/next2.png" class="next"></a></p>
        </li>
        <li>
            <span>使用红包</span><p>{if condition="$item.red_id"}<img src="__STATIC__/img_user/new_close.png" style="float: left;margin:12.5px 10px 0 0;vertical-align:middle;" onclick="del_choose_red({$item.red_id})" />{/if}<a href="javascript:red_packet({$i});"><span>{if condition="$item.red_id"} {$item.red_title}{else/}使用红包{/if} </span><img src="__STATIC__/img_user/next2.png" class="next"></a></p>
        </li>
        {/if}
        {/if}
        <li class="fare">
            <span>运费：</span><p><span style="color: #A2A2A2">&yen;{$item.total_freight}</span></p>
        </li>
        <li>
            <span>买家留言【50字以内】：</span><textarea name="message[]" maxlength="50" style="margin-bottom:5px;display:block;resize:none;width: 100%;height: 50px;outline: none;"></textarea>
        </li>
        <li  class="last">
            <p>共<font id="total_num_{$k}">{$item.total_number}</font>件商品 合计:&yen;<span id="total_{$k}" class="he">{$item.total_sum}</span></p>
            <!--<input type="hidden" name="total_price[]" value="{$item.total_sum}"  />-->
        </li>
    </ul>
    {/volist}
    <div class="footer" style="bottom: 0;">
        <input type="hidden" name="trimData" value="{$trimData}" />
        <p>总计：&yen;<font id="prices">{$total.zong_price}</font><span id="together"></span></p>
        <span class="submit" id="sub">   提交   </span>
    </div>
</form>
</div>
{include file="public/src" /}
<script>
//选择店铺优惠券(每个店铺选择一次)
    function choose_ticket(i){
        var storage = window.sessionStorage;
        storage.shop_id = $('#shop_id_'+i).val();   //对应店铺id
        storage.total_price = $('#total_'+i).text();   //单店铺合计(含运费)
        storage.setItem('order_yes_url',window.location.href);
        window.location.href = "{:url('mobile/user_info/my_coupon_index')}?act=order";
    }
//选择我的红包(只可以选择一次)
    function red_packet(i){
        var storage = window.sessionStorage;
        storage.red_shop_id = $('#shop_id_'+i).val();   //红包对应店铺id
        storage.total_price = $('#prices').text();   //订单合计(含运费)
        storage.setItem('order_yes_url',window.location.href);
        window.location.href = "{:url('mobile/user_info/packet')}?act=order";
    }
//取消选择的优惠券
    function del_choose(coupon_id){
        var coupon = sessionStorage.getItem('coupon_id');
        var couponArr = JSON.parse(coupon);
        for (var i in couponArr){
            if (coupon_id == couponArr[i]){
                delete couponArr[i];  //删除此项
            }
        }
        var url = window.location.href;   //当前url
        if (url.indexOf('coupon_id=') > 0){
            var urlArr = url.split('&');   //第一个参数为cart_id;
            for (var o=0;o < urlArr.length; o++){
                if (urlArr[o].indexOf('coupon_id=') == 0){
                    urlArr[o] = "coupon_id="+JSON.stringify(couponArr);
                }
            }
            url = urlArr.join('&');
        }
        window.location.href = url;

    }
//取消选择的红包
    function del_choose_red(red_id){
        var url = window.location.href;   //当前url
        if (url.indexOf('red_packet_id=') > 0){
            var urlArr = url.split('&');   //第一个参数为cart_id;
            for (var o=0;o < urlArr.length; o++){
                if (urlArr[o].indexOf('red_packet_id=') == 0){
                   delete urlArr[o];
                }
            }
            url = urlArr.join('&');
        }
        window.location.href = url;
    }
//修改地址
    function change_address(){
        sessionStorage.setItem('order_yes_url',window.location.href);
        window.location.href = "{:url('mobile/user_info/address_manage')}?act=order";
    }
//跳转到店铺
    function jump_shop(id) {
        var url = "{:url('mobile/user_category/shop_index')}?shop_id="+id;
        sessionStorage.setItem('url_back',window.location.href);
        window.location.href = url;
    }
//跳转到商品详情
function jump_goods_details(id){
    sessionStorage.setItem('come_order_yes',window.location.href);
    window.location.href = "{:url('mobile/user_category/goods_details')}?goods_id="+id;
}
//返回
    function back_url(){
        window.location.href=sessionStorage.getItem('goods_order_yes_url');
    }
//表单提交
    $(function () {
        $.Tipmsg.p = null;
        $.Tipmsg.r = null;
        var demo = $('#form').Validform({
            tiptype: function (msg) {
                layer.open({content: msg, skin: 'msg', time:2});
            },
            btnSubmit:"#sub",
            tipSweep:true,
            postonce:true,
            ajaxPost:true,
            callback:function (t) {
                if (t.code == 200){

                    sessionStorage.setItem('oid',t.oid);
                    //清除红包,优惠券session
                    sessionStorage.removeItem('coupon_id');
                    sessionStorage.removeItem('red_packet_id');
                    //跳转到选择支付类型页面
                    window.location.href = "{:url('mobile/user_category/choose_pay_type')}?oid="+t.oid;

                }else{
                    layer.open({content:t.message,skin:'msg',time:2})
                }
            },
            beforeCheck:function(curform){
                //判断是否含有地址
                if ($('#address_info').text() == ''){
                    layer.open({content:'请选择收货地址',skin:'msg',time:2})
                    return false;
                }
                //判断合价是否有问题
                if ($('#prices').text() <= 0){
                    layer.open({content:'合计金额有误',skin:'msg',time:2})
                    return false;
                }
            },
        });
        demo.config({
            url:"{:url('mobile/user_category/commit_order')}",
            ajaxpost:{
                error: function () {
                    layer.open({content:'网络繁忙,请重试',skin:'msg',time:2});
                }
            }
        })
    });
</script>
</body>
</html>